﻿/*
    Copyright 2010, 2011 Eric Wong
	contact@optimalcycling.com
	http://www.optimalcycling.com
	Optimal Cycling - Advanced power pacing program for cyclists
	
	This file is part of Optimal Cycling.

    Optimal Cycling is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Optimal Cycling is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Optimal Cycling.  If not, see <http://www.gnu.org/licenses/>.
*/


using System;
using System.IO;
using System.Text;

namespace OptimalCycling
{

    /// <summary>
    /// A class that returns the OpenCL source code of the Optimal Cycling kernel as a single string.
    /// Used to compile the kernel at run time.
    /// </summary>  
    public static class CLFiles
    {
        const string clHeaderFolder = "CL Header";
        static readonly string[] clHeaders = { "Options.h", "Constants.h", "Vector.h", "Sort.h", "RandomNumberGen.h", "Interpolate.h", "PowerMetrics.h",
                                                 "SolverParams.h", "Model.h", "Integrator.h", "ObjectiveFunc.h", "Kernels.h" };

        const string clSourceFolder = "CL Source";
        static readonly string[] clSources = { "Interpolate.c", "Model.c", "Integrator.c", "ObjectiveFunc.c", "Kernels.c" };

        public static string Source()
        {
            StringBuilder sourceAggregate = new StringBuilder();
            StreamReader sourceReader;

            foreach (string aHeader in clHeaders)
            {
                sourceReader = File.OpenText(Path.Combine(clHeaderFolder, aHeader));
                sourceAggregate.Append(sourceReader.ReadToEnd());
                sourceReader.Close();
            }

            foreach (string aSource in clSources)
            {
                sourceReader = File.OpenText(Path.Combine(clSourceFolder, aSource));
                sourceAggregate.Append(sourceReader.ReadToEnd());
                sourceReader.Close();
            }

            return sourceAggregate.ToString();
        }
    }
}